/**
 * @namespace bs.ui界面功能包
 * @type {{}|*}
 */
;bs.ui = bs.ui || {};
bs.ui.center = function(domid, options, callback){
    var style = $.extend({
        position: 'absolute', //absolute or fixed
        top: '50%', //50%即居中，将应用负边距计算，溢出不予考虑了。
        left: '50%',
        zIndex: 2009,
        relative: true //相对于包含它的容器居中还是整个页面
    }, options || {});

    var me = this,
        el = $.each($(domid), function () {
            var $this = $(this);
            if (style.top == '50%') style.marginTop = -$this.outerHeight() / 2;
            if (style.left == '50%') style.marginLeft = -(($this.outerWidth() / 2));
            var outerHeight = $("body").outerHeight(),
                el_outerHeight = $this.outerHeight(),
                scrollTop = (/webkit/i.test(navigator.userAgent) ? document.body : document.documentElement).scrollTop
            clientHeight = document.documentElement.clientHeight;
            var top = ((clientHeight - el_outerHeight) / 2) + scrollTop;
            style.top = top + "px";
            style.marginTop = 0;
            if (style.relative && !$this.parent().is('body') && $this.parent().css('position') == 'static') $this.parent().css('position', 'relative');
            delete style.relative;
            //ie6
            if (style.position == 'fixed' && $.browser.version == '6.0') {
                style.marginTop += $(window).scrollTop();
                style.position = 'absolute';
                $(window).scroll(function () {
                    $this.stop().animate({
                        marginTop: $(window).scrollTop() - $this.outerHeight() / 2
                    });
                });
            }

            $this.css(style);
        });
    if (bs.util.isFunction(callback)) {
        callback.call(me, el);
    }

    return el;
};